package Class;

import java.util.HashMap;
import java.util.Map;

// 定期存款类
public class TimeRate {
    Map<Long, Double> timeDepositRate = new HashMap<>();
    public TimeRate(){
        initHashMap();
    }
    public void initHashMap(){
        this.timeDepositRate.put((long)3, 0.008);
        this.timeDepositRate.put((long)6, 0.010);
        this.timeDepositRate.put((long)12, 0.011);
        this.timeDepositRate.put((long)24, 0.012);
        this.timeDepositRate.put((long)36, 0.015);
        this.timeDepositRate.put((long)60, 0.0155);
    }
    public double getTimeInterest(double money, long month, long day){
        if(month < 3){
            DemandRate demandRate = new DemandRate();
            return demandRate.getDemandInterest(money,day);
        }
        if(3 <= month && month < 6){
            return money * this.getTimeDepositRate(3) * month / 12;
        }
        if(6 <= month && month < 12){
            return money * this.getTimeDepositRate(6) * month / 12;
        }
        if(12 <= month && month < 24){
            return money * this.getTimeDepositRate(12) * month / 12;
        }
        if(24 <= month && month < 36){
            return money * this.getTimeDepositRate(24) * month / 12;
        }
        if(36 <= month && month < 60){
            return money * this.getTimeDepositRate(36) * month / 12;
        }
        else{
            return money * this.getTimeDepositRate(60) * month / 12;
        }
    }
    public String getDepositType() {
        return "定期存款";
    }
    public double getTimeDepositRate(long month){
        // 能找到月份对应的利率
        if(this.timeDepositRate.get(month) != null)
            return this.timeDepositRate.get(month);
        else
            return -1.0;
    }
}
